﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
namespace OrganizedIN.DAL
{
    public class DataAccessLayer
    {
        
       
        public DataSet Authentication()
        {
            try
            {
                SqlService objService = new SqlService();
                return objService.RunProc("SP_Authentication", "User_Authentication");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ArrayList UserLogin(User_Login obj1)
        {
          try
          {
              ArrayList getdata = new ArrayList();
              SqlDataReader reader = null;
              SqlService objservices = new SqlService();
              String ConnectionString = objservices.ConnectionString;
              SqlConnection cn = new SqlConnection(ConnectionString);
              SqlCommand cmd = cn.CreateCommand();
              cmd.CommandText = "SP_OI_USERINFORMATIONLOGIN_FETCH";
              cmd.CommandType = CommandType.StoredProcedure;
              cn.Open();
              cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Convert.ToString(obj1.UserName);
              cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = Convert.ToString(obj1.UserPassword);
              reader = cmd.ExecuteReader();
              if (reader.Read())
              {
                  getdata.Add(reader.GetValue(0).ToString().Trim());
                  getdata.Add(reader.GetValue(1).ToString().Trim());
                  getdata.Add(reader.GetValue(3));
                  return getdata;
              }
                  return getdata;
              
          }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UserRegistrationInsert(UserRegistration obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserEmailID);
                objService.AddParameter("@FirstName", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserFname);
                objService.AddParameter("@LastName", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserLname);
                objService.AddParameter("@Gender", ssenumSqlDataTypes.ssSDT_String, 10, obj1.UserGender);
                objService.AddParameter("@DOB", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserDOB);
                objService.AddParameter("@Time_Zone", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserTimeZone);
                objService.AddParameter("@Password", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserPassword);
                objService.AddParameter("@Registration_Date", ssenumSqlDataTypes.ssSDT_DateTime, 20, Convert.ToString(obj1.UserRegistrationDate));
                objService.AddParameter("@HearAbtOrganizedin", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserHearAbtOrganizedin);
                objService.AddParameter("@AddComment", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserAddComment);
                objService.RunProc("SP_OI_UserInformation_Insert");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void GroupRegistrationInsert(UserRegistration obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserEmailID);
                objService.AddParameter("@FirstName", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserFname);
                objService.AddParameter("@LastName", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserLname);
                objService.AddParameter("@Gender", ssenumSqlDataTypes.ssSDT_String, 10, obj1.UserGender);
                objService.AddParameter("@DOB", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserDOB);
                objService.AddParameter("@Time_Zone", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserTimeZone);
                objService.AddParameter("@Password", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserPassword);
                objService.AddParameter("@Registration_Date", ssenumSqlDataTypes.ssSDT_DateTime, 20, Convert.ToString(obj1.UserRegistrationDate));
                objService.AddParameter("@HearAbtOrganizedin", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserHearAbtOrganizedin);
                objService.AddParameter("@AddComment", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserAddComment);
                objService.AddParameter("@CompanyName", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserCompanyName);
                objService.AddParameter("@Category", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserCompanyCategory);
                objService.AddParameter("@Address", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserAddress);
                objService.AddParameter("@City", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserCity);
                objService.AddParameter("@State", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserState);
                objService.AddParameter("@Country", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserCountry);
                objService.AddParameter("@ZipCode", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserZipCode);
                objService.AddParameter("@PhoneNum", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserPhoneNum);
                objService.RunProc("SP_OI_UserGroupInformation_Insert");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void ProfileDocumentInsert(MyProfileDocument obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 100, obj1.DocumentID);
                objService.AddParameter("@DocumentCreateDate", ssenumSqlDataTypes.ssSDT_String, 100, obj1.DocumentCreateDate);
                objService.AddParameter("@DocumentSummary", ssenumSqlDataTypes.ssSDT_String, 50, obj1.DocumentSummary);
                objService.AddParameter("@DocumentUpload", ssenumSqlDataTypes.ssSDT_String, 100, obj1.DocumentAttachment);
                objService.AddParameter("@DocumentPriority", ssenumSqlDataTypes.ssSDT_String, 50, obj1.DocumentPriority);
                objService.AddParameter("@DocumentRating", ssenumSqlDataTypes.ssSDT_String, 50, obj1.DocumentRating);
                objService.AddParameter("@DocumentSharerName", ssenumSqlDataTypes.ssSDT_String, 50, obj1.DocumentSharerName);
                objService.RunProc("SP_OI_User_Document_INSERT");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public  DataSet ProfileDocumentFetch(MyProfileDocument obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 100,obj1.DocumentID);
                return objService.RunProc("SP_OI_User_Document_FETCH", "User_Document");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public  DataSet ProfileDocSearch(string UserName, string strSubject, string dtmDocDate, string strPriority, string strRating, string strSort)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 100, UserName);
                objService.AddParameter("@vcrSubject", ssenumSqlDataTypes.ssSDT_String, 100, strSubject);
                objService.AddParameter("@vcrDocDate", ssenumSqlDataTypes.ssSDT_String, 100, dtmDocDate);
                objService.AddParameter("@vcrPriority", ssenumSqlDataTypes.ssSDT_String, 100, strPriority);
                objService.AddParameter("@vcrRating", ssenumSqlDataTypes.ssSDT_String, 100, strRating);
                objService.AddParameter("@vcrSort", ssenumSqlDataTypes.ssSDT_String, 100, strSort);
                return objService.RunProc("SP_OI_Document_SearchResult", "User_Document");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet Doc_ReDate(string strDocIds, string dtmRedate)
        {
            SqlService objService = new SqlService();
            DataSet ds = new DataSet();

            objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 100, strDocIds);
            objService.AddParameter("@vcrSubject", ssenumSqlDataTypes.ssSDT_String, 100, dtmRedate);
            return objService.RunProc("SP_OI_Document_Redate", "User_Document");    
           
        }

        public DataSet Doc_Rename(string strDocIds, string strDocRename)
        {
            SqlService objService = new SqlService();
            DataSet ds = new DataSet();

            objService.AddParameter("@vcrDocIDs", ssenumSqlDataTypes.ssSDT_String, 100, strDocIds);
            objService.AddParameter("@vcrDocRename", ssenumSqlDataTypes.ssSDT_String, 100, strDocRename);
            return objService.RunProc("SP_OI_Document_Rename", "User_Document");
        }

        public DataSet Doc_Delete(string strDocIds)
        {
             SqlService objService = new SqlService();
             DataSet ds = new DataSet();

             objService.AddParameter("@vcrDocIDs", ssenumSqlDataTypes.ssSDT_String, 100, strDocIds);
             return objService.RunProc("SP_OI_Document_Delete", "User_Document");
        }
        public void PaymentSetInsert(PaymentSet obj)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 50, obj.user_name);
                objService.AddParameter("@CreaditCardNo", ssenumSqlDataTypes.ssSDT_String, 50, obj.CreaditCard_No);
                objService.AddParameter("@Expiration_Month", ssenumSqlDataTypes.ssSDT_String, 20, obj.Expiration_Month);
                objService.AddParameter("@Expiration_year", ssenumSqlDataTypes.ssSDT_String, 20, obj.Expiration_Year);
                objService.AddParameter("@price", ssenumSqlDataTypes.ssSDT_Decimal, 50, obj.price);
                objService.AddParameter("@Paypal", ssenumSqlDataTypes.ssSDT_String, 50, obj.Paypal);
                objService.AddParameter("@Fromdate", ssenumSqlDataTypes.ssSDT_DateTime, 15, Convert.ToString(obj.Fromdate));
                objService.RunProc("SP_AddPaymentSetting");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void LanguageSetInsert(LanguageSet obj)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 50, obj.user_name);
                objService.AddParameter("@Primary_Name", ssenumSqlDataTypes.ssSDT_String, 50, obj.Primary_language);
                objService.AddParameter("@Lang_Name", ssenumSqlDataTypes.ssSDT_String, 50, obj.language);

                objService.AddParameter("@Fromdate", ssenumSqlDataTypes.ssSDT_DateTime, 15, Convert.ToString(obj.Fromdate));
                objService.RunProc("SP_AddLanguageSetting");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet LanguageFetch(LanguageSet obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                return objService.RunProc("SP_Getlanguage", "LanguageSetting");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet UserInformationFatch(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 50, user_name);
                return objService.RunProc("SP_GetUserInformation", "UserInformation");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdatePersonalInfo(UserRegistration obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserEmailID);
                objService.AddParameter("@FirstName", ssenumSqlDataTypes.ssSDT_String, 100, obj1.UserFname);
                objService.AddParameter("@SecurityAns", ssenumSqlDataTypes.ssSDT_String, 50, obj1.SecurityAns);
                objService.AddParameter("@SecurityPin", ssenumSqlDataTypes.ssSDT_String, 10, obj1.SecurityPin);
                objService.AddParameter("@ApproveEmail", ssenumSqlDataTypes.ssSDT_String, 50, obj1.ApproveEmail);
                objService.AddParameter("@Time_Zone", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserTimeZone);
                objService.AddParameter("@Password", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserPassword);
                objService.AddParameter("@TruncateEmailSub", ssenumSqlDataTypes.ssSDT_String, 50, obj1.TruncateEmailSub);
                objService.AddParameter("@GlobalEmailoption", ssenumSqlDataTypes.ssSDT_String, 50, obj1.GlobalEmailoption);
                // objService.AddParameter("@AddComment", ssenumSqlDataTypes.ssSDT_String, 50, obj1.UserAddComment);
                objService.RunProc("SP_UpdateUserInformation");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataSet GroupInformationFatch(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 50, user_name);
                return objService.RunProc("SP_GetGroupInformation", "GroupSetting");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void UpdateGroupInfo(GroupSettingInfo obj1)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 100, obj1.username);
                objService.AddParameter("@Group_Name", ssenumSqlDataTypes.ssSDT_String, 100, obj1.Group_Name);
                objService.AddParameter("@Group_Directory", ssenumSqlDataTypes.ssSDT_String, 50, obj1.Group_Directory);
                objService.AddParameter("@Group_ApprovelEmail", ssenumSqlDataTypes.ssSDT_String, 10, obj1.Group_ApprovelEmail);
                objService.AddParameter("@Group_TruncateEmail", ssenumSqlDataTypes.ssSDT_String, 50, obj1.Group_TruncateEmail);
                objService.AddParameter("@Group_Secquestion", ssenumSqlDataTypes.ssSDT_String, 50, obj1.Group_Secquestion);

                objService.RunProc("SP_UpdateGroup");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataSet GetCardInformation(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 50, user_name);
                return objService.RunProc("SP_getCreditCardno", "PaymentSetting");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void AddMedia_Insert(MyProfileMedia obj)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@Medie_ID", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaID);
                objService.AddParameter("@Media_Name", ssenumSqlDataTypes.ssSDT_String, 40, obj.Media_Media_Name);
                objService.AddParameter("@Media_Summary", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaSummary);
                objService.AddParameter("@Media_Subscription_Detail", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaSubscriptionDetail);
                objService.AddParameter("@Media_Rating", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaRating);
                objService.AddParameter("@Media_Status", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaStatus);
                objService.AddParameter("@Media_Share", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaSharerName);
                objService.AddParameter("@username", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaUserName);
                objService.AddParameter("@Media_Path_Offline", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaOfflinePath);
                objService.AddParameter("@Media_Path_Online_ID", ssenumSqlDataTypes.ssSDT_String, 40, obj.Media_OnlineURL_ID);
                objService.AddParameter("@CreatedDate", ssenumSqlDataTypes.ssSDT_String, 40, obj.Media_CreateDate);
                objService.RunProc("Sp_Add_USER_MEDIA");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet MediaFetch_Archive(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 50, user_name);

                return objService.RunProc("SP_Media_Fetch_Archive", "USER_MEDIA");


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet MediaFetch(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 50, user_name);

                return objService.RunProc("SP_Media_Fetch", "USER_MEDIA");


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Media_AddArchive(string MediaID)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@Medie_ID", ssenumSqlDataTypes.ssSDT_String, 50, MediaID);

                objService.RunProc("Sp_Media_AddArchive", "USER_MEDIA");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet MediaFetch_BookMark(string user_name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 50, user_name);

                return objService.RunProc("SP_Media_Fetch_Bookmark", "USER_MEDIA");


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public DataSet MediaSearch(string Title, string Subscription, string Share, string Rating, string Date, string username, string Type, string sort)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@vcrUserName", ssenumSqlDataTypes.ssSDT_String, 100, username);
                objService.AddParameter("@vcrTitle", ssenumSqlDataTypes.ssSDT_String, 100, Title);
                objService.AddParameter("@vcrDate", ssenumSqlDataTypes.ssSDT_String, 100, Date);
                objService.AddParameter("@vcrType", ssenumSqlDataTypes.ssSDT_String, 100, Type);
                objService.AddParameter("@vcrRating", ssenumSqlDataTypes.ssSDT_String, 50, Rating);
                objService.AddParameter("@vcrShare", ssenumSqlDataTypes.ssSDT_String, 50, Share);
                objService.AddParameter("@vcrSubsciption", ssenumSqlDataTypes.ssSDT_String, 50, Subscription);
                objService.AddParameter("@vcrSort", ssenumSqlDataTypes.ssSDT_String, 100, sort);

                return objService.RunProc("SP_Media_SearchResult", "USER_MEDIA");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public void Media_ADDRATING(string MediaID, string Rating)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@Medie_ID", ssenumSqlDataTypes.ssSDT_String, 50, MediaID);
                objService.AddParameter("@Media_Rating", ssenumSqlDataTypes.ssSDT_String, 50, Rating);

                objService.RunProc("Sp_Media_AddRating", "USER_MEDIA");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Media_Rename(string MediaID, string name)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@Medie_ID", ssenumSqlDataTypes.ssSDT_String, 50, MediaID);
                objService.AddParameter("@Media_Name", ssenumSqlDataTypes.ssSDT_String, 50, name);

                objService.RunProc("Sp_Media_Rename", "USER_MEDIA");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet Media_FetchMedia_ID()
        {
            try
            {
                SqlService objService = new SqlService();
                return objService.RunProc("SP_fetchMediaID", "USER_MEDIA");


            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void MediaDelete(string MediaID)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@MediaID", ssenumSqlDataTypes.ssSDT_String, 50, MediaID);

                objService.RunProc("SP_Media_Delete", "USER_MEDIA");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void AddMediaOnline_Insert(MyProfileMedia obj)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@Medie_ID", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaID);
                objService.AddParameter("@Media_Path", ssenumSqlDataTypes.ssSDT_String, 40, obj.MediaOnlinePath);
                objService.RunProc("SP_MEDIA_Online");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet Media_FetchBookmark(string Media_ID)
        {
            try
            {
                SqlService objService = new SqlService();
                objService.AddParameter("@MEDIA_ID", ssenumSqlDataTypes.ssSDT_String, 50, Media_ID);

                return objService.RunProc("SP_FETCHBOOKMARK", "Media_Path_Online");

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet AccountLocked_Fetch(string UserID)
        {
            SqlService objService = new SqlService();
            DataSet ds = new DataSet();
            objService.AddParameter("@Username", ssenumSqlDataTypes.ssSDT_String, 100, UserID);

            return objService.RunProc("Sp_User_AccountLocked_Fetch", "User_AccountLocked");

        }
    }
}
